﻿using FrameworkCore.Migrations;

namespace Infrastructure.Persistence;

#nullable disable

public class NetModulerDataProvider : INetModulerDataProvider
{
    public virtual bool CreateDatabaseIfNotExists(string connectionString)
    {
        throw new NotImplementedException();
    }

    public virtual bool DatabaseExists(string databaseName, string connectionString)
    {
        throw new NotImplementedException();
    }

    public virtual (string connectionString, string databaseName) GetConnectionStringFormat(string connectionString)
    {
        if (string.IsNullOrEmpty(connectionString))
            return ("", "");

        var parts = connectionString.Split(';');
        var filteredParts = parts.Where(x => !x.Contains("Catalog", StringComparison.OrdinalIgnoreCase) && !x.Contains("Database", StringComparison.OrdinalIgnoreCase));
        var databaseName = parts.Where(x => x.Contains("Catalog", StringComparison.OrdinalIgnoreCase) || x.Contains("Database", StringComparison.OrdinalIgnoreCase))
                                .FirstOrDefault()?.Split('=').LastOrDefault().Trim();
        return (string.Join(";", filteredParts), databaseName);
    }
}
